<?php
// No direct access
defined ('_JEXEC') or die();

jimport ('joomla.application.component.modellist');

class ShipnhanhModelCurrencies extends JModelList
{
	public function __construct($config = array())
	{
		if (empty($config['filter_fields'])) {
			$config['filter_fields'] = array('id', 'name', 'value');
		}
		parent::__construct($config);
	}

	function getListQuery()
	{
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$query->select('*');
		$query->from('#__sn_currency_exchange');

		// Filter search
		$search = $this->getState('filter.search');
		if (!empty($search))
		{
			$search = $db->quote('%'. $db->escape($search, true) . '%');
			$query->where('level LIKE ' . $search);
		}

		$query->order($this->getState('list.ordering', 'id') .
				' ' . $this->getState('list.direction', 'ASC'));

		return $query;
	}
	
	function getList()
	{
		$db = JFactory::getDBO();
		$query = $db->getQuery(true);
		$db->setQuery($this->getListQuery());
		
		$result = $db->loadObjectList();
		
		return $result;
	}

	protected function populateState($ordering = null, $direction = null)
	{
		// Load the filter state
		$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
		$this->setState('filter.search', $search);

		parent::populateState($ordering, $direction);
	}
}